package com.fit.dao.organization;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;

import com.fit.entities.Organization;

public class OrganizationDAOImpl implements OrganizationDAO{

	@Inject
	private Session session;
	
	public boolean save(Organization newOrganization) {
		if (newOrganization != null) {
			session.save(newOrganization);
			return true;
		}
		return false;
		
	}

	public boolean delete(Organization organization) {
		if (organization != null) {
			session.delete(organization);
			return true;
		}
		return false;
	}

	public boolean update(Organization organization) {
		if (organization != null) {
			session.update(organization);
			return true;
		}
		return false;
	}

	public List<Organization> findAll() {
		return session.createCriteria(Organization.class).list();
		
	}

	public Organization findByID(Long id) {
		if (id != null) {
			return (Organization) session.get(Organization.class, id);
		}
		return null;
	}

	public boolean deleteByID(Long id) {
		Organization p = findByID(id);
		if (p != null) {
			delete(p);
			return true;
		}
		return false;
	}
	
}
